<?php

declare (strict_types=1);
namespace App\Model;

use Hyperf\Database\Model\SoftDeletes;
use HyperfExt\Jwt\Contracts\JwtSubjectInterface;


/**
 * @property int $id
 * @property string $username
 * @property string $role
 */
class Admin extends Model implements JwtSubjectInterface
{
    //软删除
    use SoftDeletes;

    protected $table = 'admin';

    protected $primaryKey = 'id';

    public $timestamps = true;

    //能操作的字段
    protected $fillable = [
        'id',
        'nickname',
        'username',
        'password',
        'salt',
        'mobile',
        'head_pic',
        'email',
        'sex',
        'role',
        'dept_id',
        'last_login_time',
        'last_login_ip',
        'status'
    ];

    /**
     * 隐藏属性
     * @var array
     */
    protected $hidden = [
        'password',
        'salt',
        'delete_time'
    ];

    /**
     * 只读属性
     * @var array
     */
    protected $guarded = [
        'id',
        'username'
    ];

    /**
     * 字段类型或者格式转换
     * @var array
     */
    protected $casts = [
        'id' => 'integer',
        'last_login_time' => 'timestamp',
        'status' => 'integer',
    ];

    /**
     * 设置jwt的唯一key
     * @return mixed
     */
    public function getJwtIdentifier()
    {
        $primaryKey = $this->id;
        return  $primaryKey;
    }

    /**
     * 设置jwt的参数
     * @return array
     */
    public function getJwtCustomClaims(): array
    {
        return [
            'admin_id' => $this->id,
            'username' => $this->username,
            'role' => $this->role
        ];
    }

}